const carouselImages = document.getElementById('carouselImages');
const totalSlides = 3;
let currentSlide = 0;
let autoplayInterval;

// 自动轮播函数
function startAutoplay() {
    autoplayInterval = setInterval(() => {
        nextSlide();
    }, 3000); // 3秒切换一次
}

// 下一张图片
function nextSlide() {
    currentSlide = (currentSlide + 1) % totalSlides;
    updateCarousel();
}

// 上一张图片
function prevSlide() {
    currentSlide = (currentSlide - 1 + totalSlides) % totalSlides;
    updateCarousel();
}

// 更新轮播位置
function updateCarousel() {
    carouselImages.style.transform = `translateX(-${currentSlide * 1920}px)`;
}

// 鼠标悬停暂停轮播 - 修改为监听 container
const carouselContainer = document.querySelector('.carousel-container');
carouselContainer.addEventListener('mouseenter', () => {
    clearInterval(autoplayInterval);
});

// 鼠标离开恢复轮播
carouselContainer.addEventListener('mouseleave', () => {
    startAutoplay();
});

// 初始化轮播
startAutoplay();